<?php defined('SYSPATH') or die('No direct script access.');
$ss         = Session::instance();
$mydatetime = Helper_MyDateTime::factory();
$arraylist  = Helper_ArrayList::factory();
$display    = Helper_DisplayItems::factory();

$r          = Request::current();
$action     = $r->uri2();

$kriteria   = $ss->get('kriteria');
?>

<SCRIPT language="JavaScript">
<!--
		
function checkPost() {
			if (document.updatePost.tgl.value=="-")
			{
				alert("Masukan Tanggal !");
				document.updatePost.tgl.focus();
				return false;
			}

			if (document.updatePost.id_karyawan.value=="0")
			{
				alert("Pilih ID Karyawan !");
				document.updatePost.id_karyawan.focus();
				return false;
			}
			if (document.updatePost.id_truk.value=="0")
			{
				alert("Pilih ID Truk !");
				document.updatePost.id_truk.focus();
				return false;
			}
			
		}

//-->
</SCRIPT>

<?php 
	echo View::factory('module/apps_breadcrumb')
		->set('breadcrumbs',
			array(
				0=>array(
					'address'=>'index',
					'text'=>'Dashboard'
				),
				1=>array(
					'address'=>NULL,
					'text'=>"Surat Perintah Kerja Perbaikan"
				)
			)
		)
		->render();
?>

<?php echo View::factory('module/apps_message')->render(); ?>

<div class="row-fluid">
	<div class="span12">
		<div class="span5">
			<div class="row-fluid"> 
				<div class="span12">
					<?php echo Form::open($action.URL::query(array()), array('enctype'=>'multipart/form-data','name'=>'updatePost2', 'onSubmit'=>'return checkPost()'))?>
					<?php echo Form::hidden('command','')?>
					<div>
				   		<?php
							echo Form::select('key', array('0'=>'pilih','id'=>'ID','tgl'=>'Tanggal'),'',
							array
							(
								'id'=>'key',
								'class'=>'span3',
								'placeholder'=>''
							)
						);
						?>
				   		<?php
							echo Form::input('value',"",
							array
							(
								'id'=>'value',
								'class'=>'span5',
								'placeholder'=>''
							)
						);
						?>
					<?php echo Form::submit('submit','submit',array('class'=>'btn btn-inverse')) ?>
					</div>

					<?php echo form::close(); ?>

				</div>
			</div>
			<!-- User Table Starts -->
			<div class="row centered-margin">
				<div class="head-list">		
					
					<div class="span12">
						<div style="border-top: 1px solid black;">
							<?php echo Form::open($action.URL::query(array()), array('enctype'=>'multipart/form-data','name'=>'', 'method'=>'GET'))?>
							<?php echo Form::hidden('command','')?>
						   		Page <?php
									echo Form::select('page', array('1'=>'1','2'=>'2','3'=>'3','4'=>'4','5'=>'5','6'=>'6','7'=>'7','8'=>'8','9'=>'9','10'=>'10'),'',
									array
									(
										'id'=>'page',
										'class'=>'span2',
										'style'=>'margin-top: 5px;'
									)
								);
								?>
						   		Item Per Page <?php
									echo Form::select('rpp',array('5'=>'5','10'=>'10','15'=>'15','20'=>'20','25'=>'25','30'=>'30','35'=>'35','40'=>'40'),'',
									array
									(
										'id'=>'rpp',
										'class'=>'span2',
										'style'=>'margin-top: 5px;'
									)
								);
								?>
							<?php echo Form::submit('submit','submit',array('class'=>'btn btn-danger btn-small')) ?>

							<?php echo form::close(); ?>
						</div>
					</div>
					
				</div>
				</div>
				<div class="row-fluid">
				<div class="box" style="clear: right;">
					<div class="box-content">
						<table class="table table-bordered table-striped table-condensed table-hover">
						  <thead>
							  <tr>
								  <th width="100">ID</th>
								  <th width="">Tgl</th>                                     
								  <th width="80">action</th>                                           
							  </tr>
						  </thead>   
						  <tbody>
							<?php if(empty($spkplists)) { ?>
							  <tr valign="middle">
							    <td colspan="6" valign="middle" style="text-align: center;"><strong>Tidak ada data tersedia.</strong></td>
							  </tr>
							<?php } else { ?>
							  <?php foreach($spkplists as $spkplist) { ?>
								<tr>
									<td><?php echo $spkplist['id'] ?></td>
									<td><?php echo $mydatetime->mktime_from_sql($spkplist['tgl'],'Y-m-d') ?></td>
									<td style="text-align: center;">
									<a href="<?php echo 'print'.URL::query(array('command'=>'print_perintah_kerja_perbaikan','table'=>'surat_perintah_kerja_perbaikan','id'=>$spkplist['id'])) ?>" target="blank"><?php echo HTML::image('assets/global/images/print.png')?></a>&nbsp;
							      <a href="<?php echo 'spkp'.URL::query(array('id'=>$spkplist['id'])) ?>"><?php echo HTML::image('assets/global/images/edit.png')?></a>&nbsp;
							      <a href="<?php echo 'spkp'.URL::query(array('command'=>'delete','id'=>$spkplist['id'])) ?>" onclick="return confirm('Are you sure?');"><?php echo HTML::image('assets/global/images/delete.png')?></a>
									</td>
								</tr>
							  <?php } ?>
							<?php } ?>
						  </tbody>
						</table>
						
						<div class="pagination pagination-centered">
							<?php echo $pagination; ?>
						</div>
						
					</div>
				</div>
			</div>
			<!-- User Table End -->
		</div>
		<div class="span7">
			<!-- Forms Starts -->
			<div class="row-fluid">
				<!-- Main Container Starts -->
				<div class="span12 outer-well">
				
					<div class="row-fluid">
						
						<!-- Left Container Starts -->
						<div class="span12">
							
							<!-- User Data Starts -->
							<div class="row-fluid"> 
								<?php echo Form::open($action.URL::query(array('id'=>$spkp_update['id'])), array('class'=>'form-horizontal','enctype'=>'multipart/form-data','name'=>'updatePost', 'onSubmit'=>'return checkPost()'))?>
								<fieldset class="well">
								<font style=""><a href="<?php echo 'spkp'.URL::query(array('command'=>NULL,'id'=>NULL)) ?>" class="btn btn-warning ">Tambah Baru</a></font>
									<?php if(!empty($spkp_update['id'])) { ?>
									<?php echo Form::hidden('command','update')?>
									<?php } else { ?>
									<?php echo Form::hidden('command','create')?>
									<?php } ?>
								  <legend>Surat Perintah Kerja Perbaikan</legend>
								  <div class="control-group">
										<label class="control-label" for="id">ID PO</label>
										<div class="controls">
										 <?php $idmax = $display->show_max_id('surat_perintah_kerja_perbaikan','id'); ?>
										<?php $a = substr($idmax, 4); ?>
										<?php $b = $a+1; ?>
								    	<b style="margin: 10px;font-size: 14px;"><?php echo (!empty($spkp_update['id']) ? $spkp_update['id'] : 'SPKP'.$b) ?></b>
										<input type='hidden' name='id' value='<?php echo (!empty($spkp_update['id']) ? $spkp_update['id'] : 'SPKP'.$b); ?>'>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label" for="tgl">Tgl</label>
										<div class="controls">
								    <?php
											echo Form::input('tgl', $mydatetime->mktime_from_sql($spkp_update['tgl'],'Y-m-d'),
											array
											(
												'id'=>'tgl',
												'class'=>'span7',
												'placeholder'=>'tgl'
											)
										);
										?>
										<script>
										  AnyTime.picker( "tgl",
										    { format: "%Y-%m-%d"} );
										</script>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label" for="id_karyawan">ID Karyawan</label>
										<div class="controls">
								    <?php
											echo Form::select ('id_karyawan',$arraylist->default_array2('users'), $spkp_update['id_karyawan'],
											array(
												'id'=>'id_karyawan',
												'rel'=>'chosen',
												'placeholder'=>'ID Karyawan'
											)
											);
										?>
										</div>
									</div>

									<div class="control-group">
										<label class="control-label" for="id_karyawan">ID truk</label>
										<div class="controls">
								    <?php
											echo Form::select ('id_truk',$arraylist->default_array2('master_truk'), $spkp_update['id_truk'],
											array(
												'id'=>'id_truk',
												'rel'=>'chosen',
												'placeholder'=>'ID truk'
											)
											);
										?>
										</div>
									</div>

								  <?php echo Form::submit('submit','save',array('class'=>'btn btn-inverse btn-primary pull-right')) ?>
								</fieldset>
								<?php echo Form::close()?>
							</div>
							<!-- User Data End -->
							
						</div>
						<!-- Left Container End -->
					</div>
								
				</div>
				<!-- Main Container End -->
			</div>
			<!-- Forms End -->
		</div>
	</div>
</div>








